package com.ruoyi.plus.pub.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.TreeEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.stream.Collectors;

/**
 * 资源分类对象 pub_resources_class
 *
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@TableName("pub_resources_class")
public class PubResourcesClass extends TreeEntity<PubResourcesClass> implements Serializable{
    private static final long serialVersionUID = 1L;

    /** 主键id */
    @TableId(value = "id")
    private Long id;

    /** 资源分类名称 */
    @Excel(name = "资源分类名称")
    @TableField(value = "name")
    private String name;

    /** 路径 */
    @Excel(name = "路径")
    @TableField(value = "path")
    private String path;

    /** 文件夹路径 */
    @Excel(name = "文件夹路径")
    @TableField(value = "dir_path")
    private String dirPath;

    @JsonIgnore
    public TreeSelect toTreeSelect(PubResourcesClass pubResourcesClass) {
        TreeSelect treeSelect = new TreeSelect();
        treeSelect.setId(pubResourcesClass.getId());
        treeSelect.setLabel(pubResourcesClass.getName());
        treeSelect.setTreeEntity(pubResourcesClass);
        treeSelect.setChildren(pubResourcesClass.getChildren().stream().map(o -> o.toTreeSelect(o)).collect(Collectors.toList()));
        return treeSelect;
    }

}
